package com.yjhb.android.sbz.activity;

import android.widget.TextView;

import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.FriendMoney;
import com.yjhb.android.sbz.fragment.mypromotionfrend.OneLevelFriendFragment;
import com.yjhb.android.sbz.fragment.mypromotionfrend.TwoLevelFriendFragment;
import com.yjhb.android.sbz.mvp.mypromotionfriend.PromotionFriendsPresenter;
import com.jojo.android.zxlib.adapter.FragmentAdapter;
import com.jojo.android.zxlib.base.BaseFragment;
import com.jojo.android.zxlib.base.mvp.CommonView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 创建者 zx
 * 创建时间 2020/12/29 15:16
 */
public class PromotionFriendsActivity extends BaseActivity<PromotionFriendsPresenter> implements CommonView<FriendMoney> {
    private final String TAG = "PromotionFriendsActivity";

    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.today_tv)
    TextView todayTv;
    @BindView(R.id.pile_tv)
    TextView pileTv;

    private List<BaseFragment> fragments = new ArrayList<>();

    @Override
    protected PromotionFriendsPresenter initPresenter() {
        return new PromotionFriendsPresenter(this);
    }

    @Override
    protected boolean isCheckLogin() {
        return true;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_promotion_friends;
    }

    @Override
    protected void initUI() {
        fragments.add(new OneLevelFriendFragment());
        fragments.add(new TwoLevelFriendFragment());
        viewpager.setAdapter(new FragmentAdapter(getSupportFragmentManager(), fragments));
        tabLayout.setupWithViewPager(viewpager);
        tabLayout.getTabAt(0).setText(fragments.get(0).getTitle());
        tabLayout.getTabAt(1).setText(fragments.get(1).getTitle());
    }

    @Override
    protected void initData() {
        presenter.getFriendMoney();
    }

    @Override
    protected void regEvent() {

    }

    @OnClick(R.id.back)
    void back() {
        finish();
    }


    @Override
    public void onWait() {

    }

    @Override
    public void onSuccess(FriendMoney data) {
        if (data != null) {
            todayTv.setText("今日收益：" + data.getToday() + "元");
            pileTv.setText("累积收益：" + data.getTotal() + "元");
        } else {
            todayTv.setText("今日收益：--元");
            pileTv.setText("累积收益：--元");
        }
    }

    @Override
    public void onFailure(int code, String msg) {
        todayTv.setText("今日收益：--元");
        pileTv.setText("累积收益：--元");
    }
}
